//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    loadText: "点击加载更多",
    userInfo: {},
    hasUserInfo: false,
    heheda: [],
    num1: 4,
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
    ],
    apptext: [
      "第一个模块",
      "第二个模块",
      "第三个模块",
      "第四个模块",
    ],
    hehe: [
      { img: "../../static/images/max_03.png", name: "饮品" },
      { img: "../../static/images/max_04.png", name: "饼干" },
      { img: "../../static/images/max_05.png", name: "薯片" },
      { img: "../../static/images/max_06.png", name: "甜食" },
      { img: "../../static/images/max_07.png", name: "肉制品" }
    ],
    hehe1: [
      { img: "../../static/images/max_03.png", name: "饮品" },
      { img: "../../static/images/max_04.png", name: "饼干" },
      { img: "../../static/images/max_05.png", name: "薯片" },
      { img: "../../static/images/max_06.png", name: "甜食" },
      { img: "../../static/images/max_07.png", name: "肉制品" },
      { img: "../../static/images/max_03.png", name: "饮品" },
      { img: "../../static/images/max_04.png", name: "饼干" },
      { img: "../../static/images/max_05.png", name: "薯片" },
      { img: "../../static/images/max_06.png", name: "甜食" },
      { img: "../../static/images/max_07.png", name: "肉制品" }
    ],
    indicator: true,
    jiange: 4000,
    zidong: true,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),

  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  dianji(e) {
    console.log(e)
    let name = e.currentTarget.dataset.quanbu.name
    wx.navigateTo({
      url: `/pages/cart/cart?name=${name}`
    })
  },
  onLoad: function () {
    let hehe = this.data.hehe1.slice(0, 4)

    this.setData({
      heheda: hehe
    })
    console.log(this.data.heheda)
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading()
    setTimeout(function () {
      wx.hideNavigationBarLoading()
      wx.stopPullDownRefresh()
    },2000)

  },
  jiazai() {
    let san = this.data.num1 + 4
    let num1 = this.data.num1
    let hehe = this.data.hehe1.slice(0, san)
    console.log(hehe)
    this.setData({
      num1: san
    })
    wx.showToast({
      title: '加载中',
      loadtext: "数据请求中",
      duration: 1000,
      icon: "loading",

    })
    setTimeout(() => {
      this.setData({
        heheda: hehe
      })
    }, 1000)


  }
})
